package it.polimi.politics.ejb.entities;

import it.polimi.politics.dto.ReferendumDTO;

import java.io.Serializable;

import javax.persistence.*;

import java.util.List;


/**
 * The persistent class for the referendum database table.
 * 
 */
@Entity
@NamedQueries({
@NamedQuery(name="Referendum.findProposte", query="SELECT r FROM Referendum r WHERE r.stato=0 "),
@NamedQuery(name="Referendum.findApprovati", query="SELECT r FROM Referendum r WHERE r.stato=1 "),
@NamedQuery(name="Referendum.findAll", query="SELECT r FROM Referendum r"), })
public class Referendum implements Serializable {
	
	public static final String FIND_Proposte = "Referendum.findProposte";
	public static final String FIND_Approvati = "Referendum.findApprovati";
	
	public static final String FIND_ALL = "Referendum.findAll";
	
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int idreferendum;

	@Lob
	private String propostareferendum;

	private int stato;
	
	private String titolo;

	//bi-directional many-to-one association to Votoreferendum
	@OneToMany(mappedBy="referendum")
	private List<Votoreferendum> votoreferendums;

	//bi-directional many-to-many association to Utenti liketable PROPOSTE
	@ManyToMany(mappedBy="referendums1")
	private List<Utenti> utentis1;

	//bi-directional many-to-many association to Utenti partecipazione
	@ManyToMany(mappedBy="referendums2")
	private List<Utenti> utentis2;

	public Referendum() {
	}
	
	public Referendum(ReferendumDTO referendum) {
		this.idreferendum=referendum.getIdReferendum();
		this.propostareferendum=referendum.getTestoProposta();
		this.stato=referendum.getStato();
		this.titolo=referendum.getTitolo();
		
	}
	
	

	public int getIdreferendum() {
		return this.idreferendum;
	}

	public void setIdreferendum(int idreferendum) {
		this.idreferendum = idreferendum;
	}

	public String getPropostareferendum() {
		return this.propostareferendum;
	}

	public void setPropostareferendum(String propostareferendum) {
		this.propostareferendum = propostareferendum;
	}

	public int getStato() {
		return this.stato;
	}

	public void setStato(int stato) {
		this.stato = stato;
	}

	public List<Votoreferendum> getVotoreferendums() {
		return this.votoreferendums;
	}

	public void setVotoreferendums(List<Votoreferendum> votoreferendums) {
		this.votoreferendums = votoreferendums;
	}

	public Votoreferendum addVotoreferendum(Votoreferendum votoreferendum) {
		getVotoreferendums().add(votoreferendum);
		votoreferendum.setReferendum(this);

		return votoreferendum;
	}

	public Votoreferendum removeVotoreferendum(Votoreferendum votoreferendum) {
		getVotoreferendums().remove(votoreferendum);
		votoreferendum.setReferendum(null);

		return votoreferendum;
	}

	public List<Utenti> getUtentis1() {
		return this.utentis1;
	}

	public void setUtentis1(List<Utenti> utentis1) {
		this.utentis1 = utentis1;
	}

	public List<Utenti> getUtentis2() {
		return this.utentis2;
	}

	public void setUtentis2(List<Utenti> utentis2) {
		this.utentis2 = utentis2;
	}

	public String getTitolo() {
		return titolo;
	}

	public void setTitolo(String titolo) {
		this.titolo = titolo;
	}

}